cmake_minimum_required(VERSION 3.16)
project(2048Game VERSION 1.0.0 LANGUAGES CXX)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找 Qt
find_package(Qt6 COMPONENTS Core Widgets REQUIRED)

# 如果找不到 Qt6，尝试 Qt5
if(NOT Qt6_FOUND)
    find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
endif()

# 启用自动 MOC、UIC 和 RCC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# 包含当前目录
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# 源文件
set(SOURCES
    src/main.cpp
    src/GameBoard.cpp
    src/GameController.cpp
    src/Tile.cpp
)

# 头文件（需要 MOC 处理的文件）
set(HEADERS
    src/GameBoard.h
    src/GameController.h
)

# 创建可执行文件
add_executable(2048Game ${SOURCES} ${HEADERS})

# 链接 Qt 库
if(Qt6_FOUND)
    target_link_libraries(2048Game Qt6::Core Qt6::Widgets)
else()
    target_link_libraries(2048Game Qt5::Core Qt5::Widgets)
endif()

# 复制样式表
configure_file(src/styles.qss ${CMAKE_CURRENT_BINARY_DIR}/styles.qss COPYONLY)

# 设置输出目录
set_target_properties(2048Game PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# Windows 特定设置
if(WIN32)
    set_target_properties(2048Game PROPERTIES
        WIN32_EXECUTABLE TRUE
    )
endif()
